package com.softeng.network.chess;


import javax.swing.JFrame;

public class Knight extends ChessPiece{
			
	//-----------------------------------------------------------------------------------------------
	
	Knight(String color){
		
		idString = "knight";
		this.color = color;
		
		if (color == "white"){
			this.pieceString = "resources/assets/knight_white.gif";
		}else{
			this.pieceString = "resources/assets/knight_black.gif";
		}

	}
	
	//-----------------------------------------------------------------------------------------------
	
	Knight(String color, int position, JFrame window){

		this(color);
		
		addPieceImage(position, window, this.pieceString);
		
	}
	
	//-----------------------------------------------------------------------------------------------
	
	// Sees if a particular move is a move that a Knight is allowed to make
	public boolean validMove(int currentPosition, int position, ChessPiece[] boardArray){
		
		boolean validMove = false;
		int currentRow = getRowFromPos(currentPosition);
		int currentCol = getColFromPos(currentPosition);
		int nextRow = getRowFromPos(position);
		int nextCol = getColFromPos(position); 
		
		if((nextRow == (currentRow + 1)) && (nextCol == (currentCol + 2))){
			validMove = true; 
			System.out.println("Knight moves, valid move = true (1,2)");
		}
		else if((nextRow == (currentRow + 1)) && (nextCol == (currentCol - 2))){
			validMove = true; 
			System.out.println("Knight moves, valid move = true (1,-2)");
		}
		else if(nextRow == ((currentRow - 1)) && (nextCol == (currentCol + 2))){
			validMove = true; 
			System.out.println("Knight moves, valid move = true (-1,2)");
		}
		else if((nextRow == (currentRow - 1)) && (nextCol == (currentCol - 2))){
			validMove = true; 
			System.out.println("Knight moves, valid move = true (-1,-2)");
		}
		//----------------------------------------------------------------------
		else if((nextRow == (currentRow + 2)) && (nextCol == (currentCol + 1))){
			validMove = true; 
			System.out.println("Knight moves, valid move = true (2,1)");
		}
		else if((nextRow == (currentRow + 2)) && (nextCol == (currentCol - 1))){
			validMove = true; 
			System.out.println("Knight moves, valid move = true (2,-1)");
		}
		else if((nextRow == (currentRow - 2)) && (nextCol == (currentCol + 1))){
			validMove = true; 
			System.out.println("Knight moves, valid move = true (-2,1)");
		}
		else if((nextRow == (currentRow - 2)) && (nextCol == (currentCol - 1))){
			validMove = true; 
			System.out.println("Knight moves, valid move = true (-2,-1)");
		}
		
		return validMove; 
		
	}
	
}
